package dk.almbrand.microservice.circuitbreaker.states;

import dk.almbrand.microservice.circuitbreaker.CircuitBreaker;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Closed extends CircuitBreakerState {
    Logger logger = LoggerFactory.getLogger(Closed.class);

    public Closed(CircuitBreaker circuitBreaker) {
        super(circuitBreaker);
        circuitBreaker.resetFailureCount();
        logger.info("closed");
    }

    @Override
    public void exceptionOccurred(Exception e) {
        super.exceptionOccurred(e);
        if (circuitBreaker.thresholdReached())
            circuitBreaker.moveToOpenState();
    }
}
